<!DOCTYPE html>
<meta name="csrf-token" content="{{ csrf_token() }}">
@extends('layouts.admin_common') @section('content')
<head>
@if(app('env')=='production')
<link rel="stylesheet" href="{{ secure_asset('/css/sale.css') }}">
<script src="{{ secure_asset('js/goods.js') }}"></script>
<!-- <script src="{{ secure_asset('js/jquery-3.3.1.min.js') }}"> -->
<script src="{{ secure_asset('laydate/laydate.js') }}"></script>
@else
<link rel="stylesheet" href="{{ asset('/css/sale.css') }}">
<script src="{{ asset('js/goods.js') }}"></script>
<!-- <script src="{{ asset('js/jquery-3.3.1.min.js') }}"> -->
<script src="{{ asset('laydate/laydate.js') }}"></script>
@endif
<script>
    $(function(){
        $('#goodCode').blur( function(){
            var goodCode = $('#goodCode').val();
            $.ajax({
                type: 'POST',
                url: "../checkJson",
                data: {goodCode: goodCode},
                dataType: 'json',
                success: function(status){
                	var $info = "";
                    if (status == 1) {
                    	$info="商品コードが存在しました！";
                        $('#goodCodeCheck').css("color","red");
                    } else {
                    	$info="使用できます！";
                        $('#goodCodeCheck').css("color","#43CD80");
                    }
                    $("#goodCodeCheck").html($info);
                }
            });
        })
    })
</script>
<script>
function modelDelete(goodModelId){
	if (false === confirm('削除しますか？') )return;
     $.ajax({
         type: 'POST',
         url: "../deleteJson",
         data: {goodModelId: goodModelId},
         dataType: 'json',
         success: function(status){
         	var $info = "";
             if (status == 1) {
            	 $('#t'+goodModelId).remove();
             	$info="削除成功！";
                 $('#updateDeleteModel').css("color","#43CD80");
             } else {
             	$info="削除失敗！";
                 $('#updateDeleteModel').css("color","red");
             }
             $("#updateDeleteModel").html($info);
         }
     });
}

</script>
<script type="text/javascript">
    function showPreview(source) {
        var file = source.files[0];
        if(window.FileReader) {
            var fr = new FileReader();
            var portrait = document.getElementById('portrait');
            fr.onloadend = function(e) {
              portrait.src = e.target.result;
            };
            fr.readAsDataURL(file);
            portrait.style.display = 'block';
        }
      }
</script>
<script src="{{ asset('laydate/laydate.js') }}"></script>
<script>

laydate.render({
	  elem: '#start_date'
	  ,lang: 'en'
	  ,type: 'datetime'
	});
laydate.render({
	  elem: '#end_date'
	  ,lang: 'en'
	  ,type: 'datetime'
	});
</script>


<script>
function clickSelectFile() {
	$('#pic').click();

}

function selectFile(){
    var files = document.getElementById('pic').files;
    if(files.length == 0){
        return;
    }
    var file = files[0];
    var reader = new FileReader();
    reader.readAsBinaryString(file);
    reader.onload = function(f){
        var result = document.getElementById("goods_image_container");
        var src = "data:" + file.type + ";base64," + window.btoa(this.result);
        result.innerHTML = '<img id="sale_image" src ="'+src+'" style="width: 360px; height: 280px;"/>';

    }
    form.append('file',file);
}
</script>
<script>
function addRow(obj){

        var obt = document.getElementById("tsuika");
        var count=0;
        obt.onclick = function () {
        count = count + 1;

        var newTr = addTable.insertRow();
        var newTd0 = newTr.insertCell();
        var newTd1 = newTr.insertCell();
        newTd0.innerHTML='<tr>'+
                    		    '<td>型番&nbsp;&nbsp;<input placeholder="型番" name="goodsModelInfo[model'+count+']" type="text" id="model" class="required" style="width: 150px;"/>&nbsp;&nbsp;'+
                    			'カラー&nbsp;&nbsp;<select id="goods_color" name="goodsModelInfo[color'+count+']" style="width: 150px;">'+
								'<option value="1">@lang('messages.goods_color_1')</option>'+
								'<option value="2">@lang('messages.goods_color_2')</option>'+
								'<option value="3">@lang('messages.goods_color_3')</option>'+
								'<option value="4">@lang('messages.goods_color_4')</option>'+
								'<option value="5">@lang('messages.goods_color_5')</option>'+
								'<option value="6">@lang('messages.goods_color_6')</option>'+
								'<option value="7">@lang('messages.goods_color_7')</option>'+
								'</select>&nbsp;&nbsp;'+
								'サイズ&nbsp;&nbsp;<select id="goods_color" name="goodsModelInfo[size'+count+']" style="width: 150px;">'+
								'<option value="1">@lang('messages.goods_size_1')</option>'+
								'<option value="2">@lang('messages.goods_size_2')</option>'+
								'<option value="3">@lang('messages.goods_size_3')</option>'+
								'</select></td>'+
                    			' <td>'+
                                ' <button type="button" id="delete_goods" class="button_delete button_normal" onclick="remove(this)"value="削除">削除</button> '+
                                '</td>'+
                    	 '</tr>';
     }
}
function addUpdateRow(obj){

    var obt = document.getElementById("updateTsuika");
    var count=0;
    obt.onclick = function () {
    count = count + 1;

        var newTr = addTable.insertRow();
        var newTd0 = newTr.insertCell();
        var newTd1 = newTr.insertCell();
    newTd0.innerHTML='<tr>'+
                		    '<td>型番&nbsp;&nbsp;<input placeholder="型番" name="goodsModelInfo[model'+count+']" type="text" id="model" class="required" style="width: 150px;"/>&nbsp;&nbsp;'+
                			'カラー&nbsp;&nbsp;<select id="goods_color" name="goodsModelInfo[color'+count+']" style="width: 150px;">'+
							'<option value="1">@lang('messages.goods_color_1')</option>'+
							'<option value="2">@lang('messages.goods_color_2')</option>'+
							'<option value="3">@lang('messages.goods_color_3')</option>'+
							'<option value="4">@lang('messages.goods_color_4')</option>'+
							'<option value="5">@lang('messages.goods_color_5')</option>'+
							'<option value="6">@lang('messages.goods_color_6')</option>'+
							'<option value="7">@lang('messages.goods_color_7')</option>'+
							'</select>&nbsp;&nbsp;'+
							'サイズ&nbsp;&nbsp;<select id="goods_color" name="goodsModelInfo[size'+count+']" style="width: 150px;">'+
							'<option value="1">@lang('messages.goods_size_1')</option>'+
							'<option value="2">@lang('messages.goods_size_2')</option>'+
							'<option value="3">@lang('messages.goods_size_3')</option>'+
							'</select></td>'+
                			' <td>'+
                            ' <button type="button" id="delete_goods" class="button_delete button_normal" onclick="remove(this)"value="削除">削除</button> '+
                            '</td>'+
                	 '</tr>';
 }
}
function remove(temp){
	$(temp).parent().parent().remove();
}
</script>
</head>

<div class="breadcrumbs_container">
	{{Breadcrumbs::render('admin.goods_master') }}</div>
<div class="system_tab_line"></div>
<body>
	<form action="../goods/save" id="goodsform" method="post"
		enctype="multipart/form-data">
		<table class="table table-condensed">
            <tr>
				<td>
					<table class="table table-condensed">
						<tr>
							<td>商品コード</td>
							<td><input type="hidden" name="goodsInfo[goods_id]"
								value="{{$goodsinfos[0]->goods_id}}">
								<input type="text" placeholder="商品コード" id="goodCode" name="goodsInfo[goods_code]"
								value="{{$goodsinfos[0]->goods_code}}">*
								<span id="goodCodeCheck"></span>
								</td>
						</tr>
						<tr>
							<td>商品名</td>
							<td><input placeholder="商品" name="goodsInfo[goods_name]"
								type="text" value="{{$goodsinfos[0]->goods_name}}"
								class="required" id="goodName" />
								*</td>
						</tr>
						<tr>
							<td>商品名カナ</td>
							<td><input placeholder="商品名カナ" name="goodsInfo[goods_kana]"
								type="text" value="{{$goodsinfos[0]->goods_kana}}"
								class="required" id="goods_kana" /></td>
						</tr>
						<tr>
							<td>カテゴリー</td>
							<td><select name="goodsInfo[category_id]" class="required" id="categoryId"
								value="{{$goodsinfos[0]->category_id}}" placeholder="カテゴリー">
									@foreach($goodsinfos[2] as $cataCode)
									<option value="{{$cataCode->category_id}}"
										<?php if ($cataCode->category_id == $goodsinfos[0]->category_id) {echo 'selected';}?>>{{$cataCode->category_name}}</option>
									@endforeach
							</select></td>
						</tr>
						<tr>
							<td>定価</td>
							<td><input placeholder="定価" name="goodsInfo[price]" type="double"
								id="price" value="{{$goodsinfos[0]->price}}" class="required" /></td>
							<td>+税</td>
						</tr>
						<tr>
							<td>JANコード</td>
							<td><input placeholder="JANコード" name="goodsInfo[jancode]"
								type="text" value="{{$goodsinfos[0]->jancode}}" class="required"
								id="janCode" /></td>
						</tr>
						<tr>
							<td>販売開始日</td>
							<td><input placeholder="販売開始日" name="goodsInfo[start_date]"
								type="datetime" id="start_date"
								value="{{$goodsinfos[0]->start_date}}" class="required" /></td>
						</tr>
						<tr>
							<td>販売停止日</td>
							<td><input placeholder="販売停止日" name="goodsInfo[end_date]"
								type="datetime" id="end_date"
								value="{{$goodsinfos[0]->end_date}}" class="required" /></td>
						</tr>
						<tr>
							<td>最小単位</td>
							<td><input type="number" name="goodsInfo[min_lot]"
								id="min_lot" value="{{$goodsinfos[0]->min_lot}}" min="1"
								 /></td>
						</tr>
						<tr>
							<td>仕入先</td>
							<td><select name="goodsInfo[supplier_id]" id="supplierId"
								value="{{$goodsinfos[0]->supplier_id}}" class="required">
									@foreach($goodsinfos[3] as $suppCode)
									<option value="{{$suppCode->supplier_id}}"
										<?php if ($suppCode->supplier_id == $goodsinfos[0]->supplier_id) {echo 'selected';}?>>{{$suppCode->supplier_name}}</option>
									@endforeach
							</select></td>
						</tr>
						<tr>
							<td>仕入通貨</td>
							<td><select name="goodsInfo[money_type]" id="money_type"
								value="{{$goodsinfos[0]->money_type}}"
								style='display: inline-block'>
									<option value="1"
										<?php if ('1' == $goodsinfos[0]->money_type) {echo 'selected';}?>>円</option>
									<option value="2"
										<?php if ('2' == $goodsinfos[0]->money_type) {echo 'selected';}?>>USD</option>
									<option value="3"
										<?php if ('3' == $goodsinfos[0]->money_type) {echo 'selected';}?>>EU</option>
							</select></td>
						</tr>
						<tr>
							<td>仕入価額</td>
							<td><input placeholder="仕入価額" name="goodsInfo[supply_price]"
								type="text" id="supply_price"
								value="{{$goodsinfos[0]->supply_price}}" class="required" /></td>
							<td>+税</td>
						</tr>
					</table>
				</td>
				<td>
					<table class="table table-condensed">
						<tr>
							<td>画像&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<label for="sample1" class="btn btn-primary button_normal">{{trans('messages.reference')}}
									<input type="file" name="photo" id="sample1"
									style="display: none;" class="btn btn-primary button_normal"
									onChange="showPreview(this)" />
							</label>
							*
							</td>
							<td></td>
						</tr>
						<tr height="300px">
							<td colspan="2"><img id="portrait"
								src="{{$goodsinfos[0]->filesrc}}"
								style="width: 360px; height: 280px;" /></td>
						</tr>

        						<?php if(empty($goodsinfos[4])):?>
        				<tr>
						<td  colspan="2">
        						<table>
        						<tr>
        							<td>型番</td>
        							<td><input placeholder="型番" name="goodsModelInfo[model0]"
        								type="text" value="" id="model"
        								class="required" style="width: 150px;"/></td>
        							<td>カラー</td>
        							<td><select id="goods_color" name="goodsModelInfo[color0]"
        								style="width: 150px;">
        									<option value="1">@lang('messages.goods_color_1')</option>
        									<option value="2">@lang('messages.goods_color_2')</option>
        									<option value="3">@lang('messages.goods_color_3')</option>
        									<option value="4">@lang('messages.goods_color_4')</option>
        									<option value="5">@lang('messages.goods_color_5')</option>
        									<option value="6">@lang('messages.goods_color_6')</option>
        									<option value="7">@lang('messages.goods_color_7')</option>
        							</select></td>
        							<td>サイズ</td>
        							<td><select id="goods_size" name="goodsModelInfo[size0]"
        								style="width: 150px;">
        									<option value="1">@lang('messages.goods_size_1')</option>
        									<option value="2">@lang('messages.goods_size_2')</option>
        									<option value="3">@lang('messages.goods_size_3')</option>
        							</select></td>
        							</tr>
        						</table>
						</td>
						</tr>
    						<?php else:?>
						<tr><td  colspan="2">
    						<table>
        						<?php $i=0;?>
        						<?php foreach ($goodsinfos[4] as $goodsModel):?>
                                 <tr id="t{{$goodsModel->goods_model_id}}" >
        							<td>

        							型番&nbsp;&nbsp;<input name="goodsModelInfo[model{{$i}}]" type="text" value="{{$goodsModel->model}}"class="required" style="width: 150px;"/>&nbsp;&nbsp;
                                    カラー&nbsp;&nbsp;<select id="web_open" name="goodsModelInfo[color{{$i}}]" style="width: 190px;">
        							       <option value="1"
        							        <?php if ('1' == $goodsModel->color) {echo 'selected';}?>>@lang('messages.goods_color_1')</option>
        									<option value="2"
        									<?php if ('2' == $goodsModel->color) {echo 'selected';}?>>@lang('messages.goods_color_2')</option>
        									<option value="3"
        									<?php if ('3' == $goodsModel->color) {echo 'selected';}?>>@lang('messages.goods_color_3')</option>
        									<option value="4"
        									<?php if ('4' == $goodsModel->color) {echo 'selected';}?>>@lang('messages.goods_color_4')</option>
        									<option value="5"
        									<?php if ('5' == $goodsModel->color) {echo 'selected';}?>>@lang('messages.goods_color_5')</option>
        									<option value="6"
        									<?php if ('6' == $goodsModel->color) {echo 'selected';}?>>@lang('messages.goods_color_6')</option>
        									<option value="7"
        									<?php if ('7' == $goodsModel->color) {echo 'selected';}?>>@lang('messages.goods_color_7')</option>
        							</select>
        							</td>
        							<td>
        							サイズ&nbsp;&nbsp;<select id="goods_size" name="goodsModelInfo[size{{$i}}]"
        								style="width: 150px;">
        									<option value="1" <?php if ('1' == $goodsModel->size) {echo 'selected';}?>>@lang('messages.goods_size_1')</option>
        									<option value="2" <?php if ('2' == $goodsModel->size) {echo 'selected';}?>>@lang('messages.goods_size_2')</option>
        									<option value="3" <?php if ('3' == $goodsModel->size) {echo 'selected';}?>>@lang('messages.goods_size_3')</option>
        							   </select>
                    					 <button type="button" id="delete_goods" class="button_delete button_normal" onclick="modelDelete('{{$goodsModel->goods_model_id}}')"value="削除">削除</button>
        							</td>

        						  </tr>
        						<?php $i++;?>
        						<?php endforeach;?>

        						</table>
        				</td></tr>
    						<?php endif;?>
						<tr><td colspan="2">
							<table id="addTable" class="table table-condensed">
					        </table>
					        </td>
						</tr>
						<tr><td colspan="2">
							<?php if(empty($goodsinfos[4])):?>
							<button type="button" class=" pure-button pure-button-primary button_normal"  value="追加" onclick="addRow();" id="tsuika" >追加</button>
							<?php else:?>
							<button type="button" class=" pure-button pure-button-primary button_normal"  value="追加" onclick="addUpdateRow();" id="updateTsuika" >追加</button>
							<span id="updateDeleteModel"></span>
							<?php endif;?></td>
						</tr>
						<tr>
							<td>WEB公開</td>
							<td><select id = "web_open" name="goodsInfo[web_open]"><option value="1"
										<?php if ('1' == $goodsinfos[0]->web_open) {echo 'selected';}?>>公開</option>
									<option value="2"
										<?php if ('2' == $goodsinfos[0]->web_open) {echo 'selected';}?>>非公開</option></select></td>
						</tr>
						<tr>
							<td>新商品</td>
							<td><input type="hidden" name="goodsInfo[new_flg]"
								value="{{$goodsinfos[0]->new_flg}}"> <input type="checkbox" name="goodsInfo[new_flg]"
								id="new_flg" value="1"
								<?php if ('1' == $goodsinfos[0]->new_flg) {echo 'checked';}?>></input></td>
						</tr>
						<tr>
							<td>トップページ表示</td>
							<td><input type="hidden" name="goodsInfo[top_show_flg]"
								value="{{$goodsinfos[0]->top_show_flg}}"> <input type="checkbox" name="goodsInfo[top_show_flg]"
								id="top_show_flg" value="1"
								<?php if ('1' == $goodsinfos[0]->top_show_flg) {echo 'checked';}?> /></td>
						</tr>

					</table>
				</td>
			</tr>

	        <tr>
				<td cospan="2"><input type="submit"
					class="pure-button pure-button-primary button_normal" value="保存"
					onclick="return checkGoodsForm();">
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<button id="reback" type="button"
						onclick="location.href='../goods'"
						class="pure-button pure-button-primary button_normal">@lang('messages.cancel')</button>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<button id="reback" type="button" onclick="window.history.go(-1)"
						class="pure-button pure-button-primary button_normal">@lang('messages.delete')</button>

					<input type="hidden" id="_token" name="_token"
					value="{{csrf_token()}}">
				</td>

			</tr>
		</table>
	</form>
</body>

@endsection


